package vip.xiaonuo.miniapp.api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.pojo.httpclient.ReturnJson;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.miniapp.api.miniappmemberuser.entity.MiniappMemberUser;
import vip.xiaonuo.miniapp.api.service.MiniAppService;
import vip.xiaonuo.miniapp.api.vo.*;
import vip.xiaonuo.sys.modular.pos.entity.SysPos;

/**
 * 访客
 */
@RestController
@Slf4j
public class VisitorApiController {

    @Autowired
    private MiniAppService miniAppService;


    /**
     * 小程序登陆接口
     */
    @GetMapping(value = "/a/v2.0/api/visitor/miniapp/login")
    public ReturnJson login(String code) throws Exception {
        return miniAppService.login(code);
    }

    /**
     * 获取全部组织
     *
     * @return
     */
    @GetMapping(value = "/a/v2.0/api/visitor/miniapp/getAllOrgs")
    public ReturnJson getAllOrgs(String name) {
        return miniAppService.getAllOrgs(name);
    }


    /**
     * 获取用户绑定手机号信息
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/miniapp/getPhone", method = RequestMethod.POST)
    public ReturnJson phone(String sessionKey, String encryptedData, String ivStr) {
        return miniAppService.getPhone(sessionKey, encryptedData, ivStr);
    }

    /**
     * 系统登陆
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/login", method = RequestMethod.POST)
    public ReturnJson login(@RequestBody VisitorAdminLoginVO login) {
        return miniAppService.login(login);
    }

    /**
     * 邀请人模糊查询
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/inviterList", method = RequestMethod.POST)
    public ReturnJson memberList(String name, String phone, Long orgId) {
        return miniAppService.memberList(name, phone, orgId);
    }

    /**
     * 访客查询接口
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/list", method = RequestMethod.POST)
    public ReturnJson list(@RequestBody VisitorApiRequestVO visitorApiRequestVO) {
        return miniAppService.list(visitorApiRequestVO);
    }

    /**
     * 访客审批
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/approval", method = RequestMethod.POST)
    public ReturnJson approval(@RequestBody VisitorApprovalVo approvalVo) {
        return miniAppService.approval(approvalVo);
    }

    /**
     * 访客提交到访
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/save", method = RequestMethod.POST)
    public ReturnJson save(@RequestBody VisitorApiSaveVO visitorApiVO) throws Exception {
        return miniAppService.save(visitorApiVO);
    }

    /**
     * 查询当前用户可选设备
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/getMemberDevice", method = RequestMethod.POST)
    public ReturnJson getMemberDevice(String inviterPhone) {
        return miniAppService.getMemberDevice(inviterPhone);
    }

    /**
     * 查询当前用户可选设备
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/getMemberStairs", method = RequestMethod.POST)
    public ReturnJson getMemberStairs(String inviterPhone) {
        return miniAppService.getMemberStairs(inviterPhone);
    }

    /**
     * 保存访客并且通过审批
     */
    @RequestMapping(value = "/a/v2.0/api/visitor/saveAndApproved", method = RequestMethod.POST)
    public ReturnJson saveAndApproved(@RequestBody VisitorApiSaveVO visitorApiVO) throws Exception {
        return miniAppService.saveAndApproved(visitorApiVO);
    }


    @RequestMapping(value = "/a/v2.0/api/member/save", method = RequestMethod.POST)
    @ApiOperation(value = "小程序录入人员", tags = "小程序接口", response = Void.class)
    public ResponseData memberSave(@RequestBody @Validated MemberApiSaveVo memberApiSaveVo) {
        miniAppService.saveMember(memberApiSaveVo);
        return ResponseData.success();
    }

    @ApiOperation(value = "小程序录入人员列表", tags = "小程序接口", response = MiniappMemberUser.class)
    @RequestMapping(value = "/a/v2.0/api/member/list", method = RequestMethod.POST)
    public ResponseData memberList(@RequestBody @Validated MemberApiQueryVo memberApiQueryVo) {
        return ResponseData.success(miniAppService.miniappMemberList(memberApiQueryVo));
    }

    @ApiOperation(value = "小程序录入人员详情", tags = "小程序接口", response = MiniappMemberUser.class)
    @RequestMapping(value = "/a/v2.0/api/member/detail", method = RequestMethod.POST)
    public ResponseData detail(@RequestBody @Validated MemberApiDetailVo detailVo) {
        return ResponseData.success(miniAppService.detail(detailVo));
    }


    @ApiOperation(value = "小程序录入人员审核", tags = "小程序接口", response = Void.class)
    @RequestMapping(value = "/a/v2.0/api/member/approval", method = RequestMethod.POST)
    public ResponseData approval(@RequestBody @Validated MemberApprovalVo memberApprovalVo) {
        miniAppService.approval(memberApprovalVo);
        return ResponseData.success();
    }

    @ApiOperation(value = "小程序职位列表", tags = "小程序接口", response = SysPos.class)
    @GetMapping(value = "/a/v2.0/api/visitor/miniapp/getAllPos")
    public ResponseData getAllPos(@ApiParam("姓名") String name) {
        return ResponseData.success(miniAppService.getAllPos(name));
    }
    @ApiOperation(value = "获取二维码", tags = "小程序接口", response = SysPos.class)
    @GetMapping(value = "/a/v2.0/api/visitor/miniapp/getCodeStr")
    public ResponseData getCodeStr(String phone,Long id) {
        return ResponseData.success(miniAppService.getCodeStr(phone,id));
    }

    @ApiOperation(value = "发送短信通知", tags = "小程序接口", response = Void.class)
    @GetMapping(value = "/a/v2.0/api/visitor/miniapp/sendMessage")
    public ResponseData sendMessage(Long id) {
        miniAppService.sendMessage(id);
        return ResponseData.success();
    }
}
